package com.findme.fecedetection.adapter

import android.support.v7.widget.RecyclerView
import android.view.View
import com.findme.fecedetection.R
import com.findme.fecedetection.base.ImageViewTang
import com.findme.fecedetection.base.JustAdapter
import com.tanguy.user.utlis.extend.click
import org.jetbrains.anko.find

/**
 * Created by dab on 2017/11/23 0023 21:05
 */
class UploadingAdapter(data: ArrayList<Any>) : JustAdapter<Any>(data, R.layout.item_uploading) {
    override fun bind(holder: RecyclerView.ViewHolder, position: Int, data: java.util.ArrayList<Any>) {
        val any = data[position]
        holder.itemView.apply {
            if (any is Int) {
                find<ImageViewTang>(R.id.iv_picture).setImageByRes(any)
                find<View>(R.id.iv_delete).visibility = View.GONE
                click(R.id.iv_picture) { onDelete?.invoke(false,position) }

            }
            if (any is String) {
                find<ImageViewTang>(R.id.iv_picture).setImageByFile(any)
                val find = find<View>(R.id.iv_delete)
                find.visibility = View.VISIBLE
                click(R.id.iv_delete) { onDelete?.invoke(true,position) }
            }
        }
    }

    var onDelete: ((delete: Boolean,position:Int) -> Unit)? = null
}